package com.menggudf.service.impl;

import com.menggudf.entity.PreviousHistory;
import com.menggudf.mapper.PreviousHistoryDao;
import com.menggudf.service.PreviousHistoryService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (PreviousHistory)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 16:58:33
 */
@Service("previousHistoryService")
public class PreviousHistoryServiceImpl implements PreviousHistoryService {
    @Resource
    private PreviousHistoryDao previousHistoryDao;

    /**
     * 通过ID查询单条数据
     *
     * @param preId 主键
     * @return 实例对象
     */
    @Override
    public PreviousHistory queryById(Integer preId) {
        return this.previousHistoryDao.queryById(preId);
    }

    /**
     * 分页查询
     *
     * @param previousHistory 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PreviousHistory> queryByPage(PreviousHistory previousHistory, PageRequest pageRequest) {
        long total = this.previousHistoryDao.count(previousHistory);
        return new PageImpl<>(this.previousHistoryDao.queryAllByLimit(previousHistory, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param previousHistory 实例对象
     * @return 实例对象
     */
    @Override
    public PreviousHistory insert(PreviousHistory previousHistory) {
        this.previousHistoryDao.insert(previousHistory);
        return previousHistory;
    }

    /**
     * 修改数据
     *
     * @param previousHistory 实例对象
     * @return 实例对象
     */
    @Override
    public PreviousHistory update(PreviousHistory previousHistory) {
        this.previousHistoryDao.update(previousHistory);
        return this.queryById(previousHistory.getPreId());
    }

    /**
     * 通过主键删除数据
     *
     * @param preId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer preId) {
        return this.previousHistoryDao.deleteById(preId) > 0;
    }
}
